﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DelegateStudy
{
    class Test {
        public  Action action;
        public Action packTest;
        public Action packTest1;
        public Func<int,String> func;
        public Func<int, int, String> func1;

        //使用lambda表达式初始化函数委托
        public Test(int index) {
            action = () => {
                Console.WriteLine("lambda表达示");
            };

            func1 = (value, value1) =>
            {
                return "" + value + " " + value1;
            };
            
        } 

        //使用匿名函数初始化函数委托
        public Test() {
            action = delegate () {
                Console.WriteLine("匿名函数");
            };
            func = delegate (int a) {
                return "a= "+a;
                
            };

            for (int i = 0; i < 10; i++) {
                packTest += () =>
                {
                    Console.WriteLine("packTest:{0}", i);
                };
            }

            
            for (int i = 0; i < 10; i++)
            {
                int index = i;
                packTest1 += () =>
                {
                    
                    Console.WriteLine("packTest1:{0}", index);
                };
            }
        }

        
    }
    class LoseNameFunc
    {
        static void Main() {
            Test t = new Test();
            t.action.Invoke();
            Console.WriteLine(t.func.Invoke(666));
            t.packTest();
            t.packTest1();
            Console.WriteLine("===================");
            Test t2 = new Test(999);
            t.action();
            
            Console.WriteLine(t2.func1(111, 222));
        }
    }
}
